(function($, window, document, undefined) {
  
  var nav = '.j-agent-nav-item'

  $(document).on('click', nav, function(e) {
    e.preventDefault()

    var $el = $(e.target)

    if (!$el.is(nav)) {
      $el = $el.parents(nav)
    }

    var index = $el.index(nav)
    
    console.log(index)

    $el
      .addClass('active')
      .siblings()
      .removeClass('active')

    $('.agent-panel-item')
      .eq(index)
      .addClass('active')
      .siblings()
      .removeClass('active')

  })

  /* 轮播 */
  new Swiper('#agent-focus', {
    autoplay: {
      delay: 8000,
      disableOnInteraction: false
    },
    on: {
      init: function() {
        var that = this

        var el = '.agent-focus-pagination-item'

        $(el).on('click', function(e) {
          e.preventDefault()
          
          var $el = $(e.target)

          if (!$el.is(el)) {
            $el = $el.parents(el)
          }

          $el
            .addClass('active')
            .siblings()
            .removeClass('active')

          that.slideTo($el.index(el))

        })
      },
      slideChange: function() {
        var el = '.agent-focus-pagination-item'

        $(el)
          .eq(this.activeIndex)
          .addClass('active')
          .siblings()
          .removeClass('active')
      }
    }
  })
  /* /轮播 */

})(jQuery, window, document)